/** 
  1.单个元素验证
  $("#b").easyvalidate([opt]); 
*
*/




/** 
 *  信息提示优先级由高到低
 *  1 页面配置 easymessage="equal:和a输入不同;length:长度不正确"  
 *  2 $.validate.defaults对象中对应验证  $.validate.easymessage.require:不能为空
 *  3 $.validate.judge 对象中对应验证返回方法 ei._error 此方法中定义的信息 
 *  4 _easyinput 对象中的 message 全局
*/
(function(){
	$.validate = $.validate || {};
	$.extend($.validate,{  
		defaults:{
			    easytip : true, // easyform 、easyinput是否 开启提示
			    realvali:true,// 失去鼠标焦点验证
			    type   : "",
			    validate: true,  //是否参与验证
			    moveLeft: 0,  //提示框横向偏移 负数向左偏移   反则向右偏移  偏移数值为  moveLeft
			    moveTop: 0,   //提示框纵向偏移  负数向上偏移  反则向下偏移  偏移数值为  moveTop
			    multipleMoveLift: -50, //针对于  checkbox 、 redio而言左右偏移量
			    multipleMoveTop:0,  //针对于  checkbox 、 redio  而言左右偏移量
	            position: "bottom",     //left ,top ,right ,bottom
	            disappear: "lost-focus",//self, other, lost-focus, none, N seconds
	            speed: "fast",
	            theme: "blue",
	            arrow: "bottom",        //top, left, bottom, right
	            "borderred" : true,
	            onshow: null,
	            onclose: null, 
	            style: {}
		},
		easymessage :{
			 "require" : "不能为空",
	    	 "char-normal":"只能为英文、数字、下划线",
	    	 "min-length":"长度不能小于最小值", 
		},
		/**
		 * validation
		 * status : 校验状态  true : 校验成功(默认) , false : 校验失败 , 
		 * rule   : 当前校验规则名称 (如 require length)
		 * val    : 当前校验对象的值
		 * msg    : 校验提示语 
		 */
		judge :{
		  "require"    : function(v) { 
 	            if (!v.val || v.val === 0) {
 	            	v.status = false;
 	            	v.msg = (v.msg ? v.msg : "不能为空");
 	            } 
 	            return v;  
 	              
 	        },
 	       "length": function (v)
           {    
               var range =v.rule.split("-"); 
               //如果长度设置为 length:6 这样的格式
               if (range.length == 1) range[1] = range[0];
                
               if (v.val.length < range[0] || v.val.length > range[1]){
            		v.status = false;
            		v.msg = (v.msg ? v.msg : (range[1] == range[0] ?  "长度应为"+range[0] : "长度应在"+range[0]+"和"+range[1]+"之间"))
                } 
                return v; 
           },
           "number" : function(v)
           {
        	   if( !( Number(v.val) ) ) {
        		   v.status = false;
        		   v.msg =  ( v.msg ? v.msg : "只能为数字");
        	   }
        	   return  v;
           },
           "integer" : function(v)
           {
        	    
        	   if( !( Number(v.val) ) &&  (   Number(v.val)  ? ( parseInt(Number(v.val)) == Number(v.val) )  : true )  ){
        		   v.status = false;
        		   v.msg = (v.msg ? v.msg :"只能为整数");
        	   } 
        		   return  v ;
           },
            "char-normal": function (v)
            {
                if (false == /^\w+$/.test(v.val)){
                   v.status = false;
          		   v.msg =  (v.msg ? v.msg :"只能为英文、数字、下划线");
                }
                return  v ;
            },

            "char-chinese": function (v)
            {
                if (false == /^([\w]|[\u4e00-\u9fa5]|[ 。，、？￥“‘！：【】《》（）——+-])+$/.test(v.val)){
                    v.status = false;
           		    v.msg =  ( v.msg ? v.msg :"只能为中文、英文、数字、下划线、中文标点符号");
                 }
                    return  v;
            },

            "char-english": function (v)
            {
                if (false == /^([\w]|[ .,?!$'":+-])+$/.test(v.val)){
                    v.status = false;
                    v.msg =  ( v.msg ? v.msg :"只能为英文、数字、下划线、英文标点符号");
                }
                 return  v
            },

            "email": function (v)
            {
                if (false == /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(v.val)){
                	 v.status = false;
                     v.msg =  ( v.msg ? v.msg :"Email格式有误");
                }
                   return v
            }, 

            "equal": function (v)
            {   
                var pair = $(v.rule) ,pairVal = pair.val() ;
                if ( pairVal != "" && (0 == pair.length || pairVal != v.val)){
                	 v.status = false;
                     v.msg =  ( v.msg ? v.msg :"匹配有误");
                }
                    return  v
            },

            "ajax": function (v)
            {
                // 为ajax处理注册自定义事件
                // HTML中执行相关的AJAX时，需要发送事件 easyinput-ajax 来通知 easyinput
                // 该事件只有一个bool参数，easyinput 会根据这个值判断ajax验证是否成功
           /*     ei.input.delegate("", "easyinput-ajax", function (e, p)
                {
                    ei.input.unbind("easyinput-ajax");

                    if (false == p)
                        return ei._error("ajax",m);
                    else
                        return ei._success_rule("ajax");
                });

                eval(p);*/
            },

            "date": function (v)
            {
                if (false == /^(\d{4})-(\d{2})-(\d{2})$/.test(v.val)){
                	 v.status = false;
                     v.msg =  ( v.msg ? v.msg :"日期格式有误");
                }
                    return v;
            },

            "time": function (v)
            {
                if (false == /^(\d{2}):(\d{2}):(\d{2})$/.test(v.val)){
               	  v.status = false;
                  v.msg =  ( v.msg ? v.msg :"时间格式有误");
                }
                  return  v;
            },

            "datetime": function (v)
            {
                if (false == /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/.test(v)){
                 	  v.status = false;
                      v.msg =  ( v.msg ? v.msg :"日期格式有误");
                }
                    return v;
            },

            "money": function (v)
            {
                if (false == /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/.test(v)){
               	  v.status = false;
                  v.msg =  ( v.msg ? v.msg :"金额格式有误");
                }
                    return v;
            },

            "uint": function (v)
            {
                v = parseInt(v.val);
                p = parseInt(p.rule);

                if (isNaN(v) || isNaN(p) || v < p || v < 0){
               	  v.status = false;
                  v.msg =  ( v.msg ? v.msg : "数字在"+v+"-"+p+"之间");
                }
                    return v;
            } 
		},
		themes:{  
		        black: {
		            color: "rgba(238,238,238,1)",
		            "background-color": "rgba(75,75,75,0.8",
		            "border": "0px solid rgba(75,75,75,0.8)",
		            "border-radius": 5
		        },
		        blue: {
		            color: "rgba(255,255,255,1)",
		            "background-color": "rgba(51,153,204,0.8)",
		            "border": "0px solid rgba(51,153,204,0.8)",
		            "border-radius": 5
		        },
		        red: {
		            color: "rgba(255,255,255,1)",
		            "background-color": "rgba(255,102,102,0.9)",
		            "border": "0px solid rgba(255,102,102,0.9)",
		            "border-radius": 5
		        },
		        white: {
		            color: "rgba(102,102,102,1)",
		            "background-color": "rgba(255,255,255,0.9)",
		            "border": "0px solid rgba(255,255,255,0.9)",
		            "border-radius": 5
		        }
    
	}});
})();




(function ($, window, document, undefined)
		{
	       var _easyform = function (container,opt){

	    	   //counter 计数成功个数 ; 
  		        var counter =  0 ,  array = [] ;
  		        var elements = null;
  		        var eles = "input:visible,select:visible,textarea:visible";
  		        if(container.is(eles) ){
  		        	elements = [container];
  		        }else{
  		        	elements = container.find(eles);
  		        } 
  		       $.each(elements,function (index, input)
	  			     {      
  		        	        var $input = $(input);
  		        	        var easyrule = $input.attr("easyrule") ;
  		        	         
  		        	        //排除关闭验证的元素
  		        	        if((opt && opt.hasOwnProperty("validate") ?  !opt["validate"] : false) || (easyrule ? easyrule.indexOf("validate:false") != -1 : false) ) return ;
  		        	        
	  	                    //排除 没有验证规则的元素
  		        	        var flag = false;
  		        	        for(var o in opt){
  		        	    	  if($.validate.judge.hasOwnProperty(o)){
  		        	    	   	flag  = true;
  		        	    	   	break;
  		        	    	  } 
  		        	        }  
  		        	        if(easyrule && flag) return ; 
  		        	        
  		        	        //排除 hidden、button、submit、checkbox、radio、file
		   	                if (input.type == "hidden" || input.type == "button" || input.type == "submit"  || input.type == "file") return;
			   	         	
		   	                var options = opt || {} ; 
			   	         	
	  	                	    options.type = input.type;   
	  	                	 
	  	                	 //失去鼠标验证
	  	                	if(options.realvali){
	  	                		
	  	                		if($.inArray(input.name) != -1) return ;
  	                			
	  	                		var $inputTemp = container.find("[name='"+input.name+"']");
	  	                		
	  	                		if($inputTemp && $inputTemp.length > 0) $input =  $inputTemp ;
  	                			
	  	                		array.push(input.name);
  	                			
	  	                		var vali = $input.easysingle(options,container);
  	                			
	  	                		if(vali && !vali.status) counter++;  
	  	                	
	  	                      //当前验证一次
	  	                	}else{ 
	  	                		
	  	                		var vali = $input.easysingle(options);
	  	                		
	  	                		if(vali && !vali.status) counter++;
	  	                		
	  	                	}  
		   			  });
	   		      return counter == 0; 
	    	   
	       }; 
//---------------------------------------对外开放校验 start-----------------------------------------------------------------------	       
		    $.fn.extend({
		    	easyform : function(opt){ //默认失去焦点, 再进行校验
		    	  _easyform(this,opt); 
		    	},
		    	valdate : function(opt){ //立即校验, 失去焦点后不参与校验
		    		var o = $.extend({},opt,{realvali:false});
		    		var flag= 	_easyform(this,o);  
		    		//定位到第一个错误提示位置
		    		if(!flag){ 
		    		    var easytipfirst = $("div[id^='easytip']:visible").filter(":first");   
		    		    var easytipId = easytipfirst.attr("id"); 
		    		    window.location.hash = null;
		    		    window.location.hash = "#"+easytipId;  
		    		} 
		    		return flag; 
		    	}
		    });  
//---------------------------------------对外开放校验 end-----------------------------------------------------------------------			     
		})(jQuery, window, document);
 

(function ($, window, document, undefined) {
	
	    var _easyinput = function (){}; 
	    
	    _easyinput.prototype = {
	    		
	       check : function(input,opt){ //过滤非校验的元素
	    	   
	    	   if(opt && opt.hasOwnProperty("validate") )   return opt.validate;
	    	   
	    	   var input = $(input) ,easyopt = input.attr("easyoption");
	    	   
	    	   if( easyopt && easyopt.indexOf("validate:false") != -1) return false;
	    	   
	    	   return true; 
	    	   
	       }, 
	    	init : function(input,options,container){ 
 
	    		 
	    		 
	    		  if(container && container.length > 0 && !input.is(container)){
	    			  
	    			  input = container.find($(input)); 
	    		  }  
    			  if(!input || input.length < 1) throw new Error(" 容器中container未发现元素该元素 input ");
	    		   
	    		  var options = options || {} ;
	    		  
	    		  this.init_validation(input,options);
	    		  
	    		  //屏蔽验证
                  if(Boolean(options.tipoptions.validate) && options.tipoptions.validate != 'false' ) {
                	  
                	  if( Boolean(options.tipoptions.realvali) && options.tipoptions.realvali != 'false'){
    	    			  
  	    			    this.init_blur(input,options); 
  	    			    
	  	    		   }else{ 
	  	    			  
	  	    			    var vali = this.validate(input,options) , _easyinput = $(input); 
	  	    			    
	  	            		if(vali && !vali.status)  this.init_tip(input,options.tipoptions,vali);  
	  	            		
	  	            		return vali;
	  	    		   }
                   }else {
                	  
                	  
                  }
	    		   
	    		  
	    		},
	    		
	    		init_validation : function(element,options){
	    			  
			        var input = $(element) ,  o = {} , r = {} , m = {} ,rules = [] ,
			        
			            rule_str = input.attr("easyrule") , _rules = !!rule_str ? rule_str.split(";") : [] ,
			        		
			            msg_str = input.attr("easymessage"), _msgs = !!msg_str ? msg_str.split(";") : [] ;
			        		 
			        //生成  {"length":"length:1-2","require":""} 格式 
			        $.each(_rules,function(i,e){  
			        	
			        		 if(!e ) return ; //continue;
			        		 
			        		 var  p = e.indexOf(":") , _r = e.substr(0, p) ;
			        		 
			        		 if (-1 == p) _r = e;
			        		 
			        		 if($.validate.judge.hasOwnProperty(_r))  r[_r] = e    //该属性是验证属性
			        			 
			        		 else  o[_r] = e.substr(p + 1);                        //该属性验证是 easyform普通属性
			        		 
			        });
			       
			        
			        //生成  {"length":"长度太长","require":"必填"} 格式 
			        $.each(_msgs,function(i,e){
			        	
		        		 if(!e ) return ; //continue;
		        		 
		        		 var  p = e.indexOf(":") , _r = e.substr(0, p) ,_m =  e.substr(p + 1);
		        		 
		        		 if($.validate.judge.hasOwnProperty(_r) && -1 != p)   m[_r] = _m ; 
		        		 
		           });
			         
			        //重写 页面上的验证
			        for(e in options){
			        	
			        	if($.validate.judge.hasOwnProperty(e)) r[e] = e +  ( options[e] || options[e] == 0  ? ":" +options[e]+"" : "") ;     
			        	
			        	else if( e == "easymessage" &&  typeof(options[e]) =="object")
			        	
			        	{
			        		for(a in options[e]){
			        			if($.validate.judge.hasOwnProperty(a))  m[a] = options[e][a];
			        		} 
			        	}
			        	
			        	else  o[e] = options[e] ;
			        	
			        }		
			     
			        
			        m =   $.extend({},$.validate.easymessage,m);
			        
			        o =   $.extend({},$.validate.defaults,o);
			        
			        //删除不验证的提示信息
			        for(var key in m){
			        	if(!r.hasOwnProperty(key)) delete m[key];
			        }
			         
			        //组装 验证
			        for (e in r)
			           {    //有:号 
			        	    var s = r[e] ;
			        	    
			        	    if(!s) continue; 
			        	    
			        	    var p = s.indexOf(":")  , param = "" ;
			              
			                if (-1 != p)   param = s.substr(p + 1); 
			                
			                rules.push({"rule" : $.validate.judge[e], "rulename":e, "param": param, "message" : m[e]});
			                
		                }  
			      
			         
			         //将验证、msg、potion写到页面 
			         var rs = "";
			         for(var key in r){
			        	 rs +=   ( key ?  (  r[key]  ?  ( r[key]+";")  :  "" )     : "" );
			         }
			         input.attr("easyrule",rs);
			         
			         var ms = "";
			         for(var key in m){
			        	 ms += (key) + ((m[key] || m[key] == 0) ? ( ":"+m[key]+";") : ";") ;
			         }
			         input.attr("easymessage",ms);
			         
			         var os = "";
			         for(var key in o){
			        	 os += (key) + ((o[key] || o[key] == 0) ? ( ":"+o[key]+";") : ";") ;
			         }
			         input.attr("easyoption",os);
			         
			         
			         options.rules = rules; 
			         options.tipoptions = o;
			         return options;
			        
	    		},
	    		
	    		init_blur : function(input,opt){
	    			    
	    			   var easyinput = $(input);
	    			   var _et = this; 
				       easyinput.blur(function ()
		                {        
				    	   
		            		var vali = _et.validate(input,opt);   
		            		if(opt.type == 'checkbox' || opt.type == "radio"){
		            			input = $("[name='"+input[0].name+"']"); 
		            		}
		            		_et.init_tip(input,opt.tipoptions,vali); 
		                });  
	    		},
	    		
	    		validate : function(input,options){
	    			
	    			var easyinput = $(input);
	    			 var  val = ""; //radio
	    			if(options.type == "checkbox" || options.type == "radio"){
	    				 val = easyinput.filter(":checked").val(); 
	    			}else{
	    				 val = easyinput.val();  
	    			}
		            
	    			var  vali =  {status : true,val : val, msg : "成功"};
	    			
		            for (var i = 0; i < options.rules.length; i++)
		            {   
		            	  var v = {status : true,val : val, rule : options.rules[i].param, msg : options.rules[i].message};
		            	      v = options.rules[i].rule(v);
		            	      
		            	  if(!v.status) return v; 
		            }
		            
		            return vali ;
		            
	    		},
	    		add_rule   : function(input,validation){
	    			 
	    			 if(!validation) return ;
	    			
                     var  input = $(input) ,  easyrule = input.attr("easyrule") ,rule = "";
	    			 
	    			 if ($.type(validation) == "object") validation = [validation];
	    			 
	    			 if($.type(validation) != "array")  return ;
	    			 
	    			 for(var j = 0 ; j < validation.length ;j++){
   					  
   					    var v = validation[j]  ,  rule = "" ; 
		    				
		    			for(var vali in v){
		    				rule += (vali+":"+ ( v[vali] ?  v[vali] :'' ) +";");
		    			} 
   				     } 
	    			 if(rule) rule = rule.substring(0,rule.length-1);
	    			 
	    			 if(easyrule) easyrule += (";"+rule);
	    			 
	    			 else easyrule = rule;
	    			 
	    			 input.attr("easyrule",easyrule); 
	    			  
	    			 //重新绑定验证
	    			 input.off("blur");  
                     this.init(input); 
	    			  
	    		},

	    		remove_rule : function(input,validation){ 
	    			
	    			 var  input = $(input) ,  easyrule = input.attr("easyrule");
	    			 
	    			 if (typeof(validation) == "string") validation = [validation];
	    			     
	    			 
	    			 if(!validation) return ;
                     if( $.type( validation ) === "array"){
                    		
	    				  var rule = "" ;
	    				  for(var j = 0 ; j < validation.length ;j++){
	    					  
	    					  var v = validation[j] ,  a  =  easyrule.split(v)  ;
	    					    
			    			  if(!a || a.length < 1) return ;
			    				
			    			   rule += a[0];
			    				
			    			   for(var i = 1 ; i <a.length ; i++){
			    					
			    					if(!a[i]) continue;
			    					
			    					var index = a[i].indexOf(";");
			    					
			    					if(index == -1) continue;
			    					
			    					rule += a[i].substr(index+1); 
			    			   } 
			    			   easyrule = rule ;
	    				  }  
	    				 //重新绑定验证
		    			 input.attr("easyrule",easyrule); 
		    			 input.off("blur");  
	                     this.init(input);   
	    			  }  
	    		},
	    		open_validate  : function(input){
	    			
	    			 var  input = $(input)  , easyoption = input.attr("easyoption");

	    			 if(easyoption){
	    				 
	    				 if(easyoption.indexOf("validate:false") != -1)  easyoption.replace("validate:false","validate:true"); 
	    				 
	    				 else easyoption += ";validate:true" ;
	    				 
	    			 } else {
	    				 
	    				 easyoption  = "validate:true" ;
	    			 }
	    			 
	    			 input.attr("easyoption",easyoption);
	    			
	    			 
	    			 input.off("blur");
	    			 
	    			 this.init(input,{validate:true}); 
	    			  
	    		},
	    		close_validate : function(input){
	    			
	    			 var  input = $(input) , easyoption = input.attr("easyoption"); 
	    			 
	    			 if(easyoption){
	    				 
	    				 if(easyoption.indexOf("validate:true") != -1)  easyoption.replace("validate:true","validate:false"); 
	    				 
	    				 else easyoption += ";validate:false" ;
	    				 
	    			 } else {
	    				 
	    				 easyoption  = "validate:false" ;
	    			 }
	    			 
	    			 input.attr("easyoption",easyoption);
	    			 
	    			 input.off("blur");
	    			 
	    			 this.init(input,{validate:false}); 
	    		},
	    		init_tip : function(input,tipoptions,validation){  
	    			 
	    			var easyinput = $(input); 

	    			var tip = easyinput.easytip(tipoptions);
	    			
	    			if (!validation.status) tip.show(validation.msg);
	    				
	    			else tip.close();
	    			
	    			    
	    		}
	    };
	    
 //---------------------------------------对外开放校验 start-----------------------------------------------------------------------	    
	    $.fn.easysingle = function (options,container)
	    {
	   	   
	    	if(options == "closeValidate" ){ //关闭所有验证、保留验证信息
	    		
	    		  var validate = new _easyinput();
	    		  
	    		      validate.close_validate(this,container);
	    	 
	    	}else if(options == "openValidate"){ //开启验证
	    		
                  var validate = new _easyinput();
	    		  
	    		      validate.open_validate(this);
	    		
	    		  return  validate.init(this);
	    		
	    	}else if(options == "addRule"){ //添加验证
	    		
	    		var validate = new _easyinput();
	    		
	    		    validate.add_rule(this,container);
	    		
	    	}else if(options == "removeRule" ){ //移出验证、不会保留被移除的验证
	    		var validate = new _easyinput();
	    		
    		    validate.remove_rule(this,container);
	    		
	    	}else  if(options == "editOption" ){ //更新属性
	    		var validate = new _easyinput();
	    		
    		    validate.remove_rule(this,container);
	    		
	    	}else {  
	    	     var check = new _easyinput();
	    	     
	    	     if(!check.check(this,options)) return true; //过滤非校验的元素
	    	     
	             return  check.init(this,options,container);
	    	}
	    	 
	    }; 
	    
//---------------------------------------对外开放校验 end-----------------------------------------------------------------------	    
	 
	    
})(jQuery, window, document); 







(function ($, window, document, undefined)
{ 
    var _easytip = function (ele, opt ,container)
    {
    	 
    	var multiple = false;
    	if(container && container.length > 0)   ele = container.find($(ele)) ;     	
    	   
    	if(ele && ele.length > 1) {ele =  ele.filter(":first");  this.multiple = true ;}  ;
    	 
        this.parent = ele , this.padding = 0  , this.id = "easytip-div-main" + ($(ele).attr("id") || $(ele).attr("id") === 0  ? $(ele).attr("id") : $(ele).attr("name")); 
         
        if(!ele || ele.length < 1) throw new Error(" 容器中container未发现元素该元素  ele ");
        
        
        
        var tipoptions = ele.attr("easytip") , tipopts = {}, opt = opt || {} ,
        
            tipoptions = (!!tipoptions ? tipoptions.split(";") : undefined); 
        
        if (!!tipoptions)
        {
	            var options = Object();
	            var index;
	            for (index in tipoptions)
	            {
	                var temps = tipoptions[index];
	                var p = temps.indexOf(":");
	
	                if (-1 == p)continue;
	
	                var temp = [];
	                temp[0] = temps.substring(0, p);
	                temp[1] = temps.substring(p + 1);
	
	                options[temp[0]] = temp[1];
	            }
	            tipopts = options;
          }  
        // 继承  根属性  、页面上的属性  、传值属性 
        this.options = $.extend({},$.validate.defaults,tipopts, opt);   
        
      
        if(this.multiple){
        	this.options.moveTop = this.options.moveTop + this.options.multipleMoveTop;
        	this.options.moveLeft = this.options.moveLeft + this.options.multipleMoveLift;
        } 
         
		 
        
    };

    _easytip.prototype = {

        init: function ()
        {
            var tip = $("#" + this.id);

            if (tip.length == 0)
            {
                $(document.body).append("<div id=\"" + this.id + "\"><div class=\"easytip-text\"></div></div>");

                tip = $("#" + this.id);
                var text = $("#" + this.id + " .easytip-text");

                tip.css({
                    "text-align": "left",
                    "display": "none",
                    "position": "absolute",
                    "z-index": "100"
                });

                text.css({
                    "text-align": "left",
                    "padding": "10px",
                    "min-width": "120px"
                });

                tip.append("<div class=\"easytip-arrow\"></div>");
                var arrow = $("#" + this.id + " .easytip-arrow");
                arrow.css({
                    "padding": "0",
                    "margin": "0",
                    "width": "0",
                    "height": "0",
                    "position": "absolute",
                    "border": "10px solid"
                });
            }

            return this;
        },

        _size: function ()
        {
            var parent = this.parent;
            var tip = $("#" + this.id);


            if (tip.width() > 300)
            {
                tip.width(300);
            }
        },

        _css: function ()
        {
            var tip = $("#" + this.id);
            var text = $("#" + this.id + " .easytip-text");
            var arrow = $("#" + this.id + " .easytip-arrow");

            text.css($.validate.themes[this.options.theme]); 
            arrow.css("border-color", "transparent transparent transparent transparent");

            if (this.options.style != null && typeof(this.options.style) == "object")
            {
                text.css(this.options.style);
            }
        },

        _arrow: function ()
        {
            var tip = $("#" + this.id);
            var text = $("#" + this.id + " .easytip-text");
            var arrow = $("#" + this.id + " .easytip-arrow");

            switch (this.options.arrow)
            {
                case "top":
                    arrow.css({
                        "left": "25px",
                        "top": -arrow.outerHeight(),
                        "border-bottom-color": text.css("borderTopColor")
                    });
                    break;

                case "left":
                    arrow.css({
                        "left": -arrow.outerWidth(),
                        "top": tip.innerHeight() / 2 - arrow.outerHeight() / 2,
                        "border-right-color": text.css("borderTopColor")
                    });
                    break;

                case "bottom":
                    arrow.css({
                        "left": "25px",
                        "top": tip.innerHeight(),
                        "border-top-color": text.css("borderTopColor")
                    });
                    break;

                case "right":
                    arrow.css({
                        "left": tip.outerWidth(),
                        "top": tip.innerHeight() / 2 - arrow.outerHeight() / 2,
                        "border-left-color": text.css("borderTopColor")
                    });
                    break;
            }
        },

        _position: function ()
        { 
            var tip = $("#" + this.id);
            var text = $("#" + this.id + " .easytip-text");
            var arrow = $("#" + this.id + " .easytip-arrow");
            var offset = $(this.parent).offset();
            var size = {width: $(this.parent).outerWidth(), height: $(this.parent).outerHeight()}; 
            var option = this.options ;
            switch (option.position)
            {
                case "top" :
                	
                    tip.css("left", offset.left - this.padding + option.moveLeft);
                    tip.css("top", offset.top - tip.outerHeight() - arrow.outerHeight() / 2 + option.moveTop);
                    this.options.arrow = "bottom";

                    break;

                case "left":

                    tip.css("left", offset.left - tip.outerWidth() - arrow.outerWidth() / 2   + option.moveLeft);
                    tip.css("top", offset.top - (tip.outerHeight() - size.height) / 2   + option.moveTop);
                    this.options.arrow = "right";

                    break;

                case "bottom":
                	
                    var left = offset.left - this.padding + option.moveLeft;
                    tip.css("left", offset.left - this.padding + option.moveLeft);
                    tip.css("top", offset.top + size.height + arrow.outerHeight() / 2   + option.moveTop);
                    this.options.arrow = "top";

                    break;

                case "right":

                    tip.css("left", offset.left + size.width + arrow.outerWidth() / 2 + option.moveLeft);
                    tip.css("top", offset.top - (tip.outerHeight() - size.height) / 2 + option.moveTop);
                    this.options.arrow = "left";

                    break;
            }

            var left = parseInt(tip.css("left"));
            var top = parseInt(tip.css("top"));

            tip.css("left", parseInt(this.options.left) + left);
            tip.css("top", parseInt(this.options.top) + top);
        },

        show: function (msg)
        {
            var tip = $("#" + this.id);
            var text = $("#" + this.id + " .easytip-text");
            var arrow = $("#" + this.id + " .easytip-arrow");
            var speed = this.options.speed;
            var disappear = this.options.disappear;
            var parent = this.parent;
            
	       	if(this.options["borderred"] && !this.multiple){ 
	       	   parent.addClass("err_border");
	    	}else if(this.multiple){
	    		parent.parent(".controll").addClass("err_border");
	    	}  
            text.html(msg); 
            this._size();
            this._css();
            this._position();
            this._arrow();
            var that = this;

            var onshow = this.options.onshow;
            var onclose = this.options.onclose;

            tip.fadeIn(speed, function ()
            {
                if (!!onshow)    onshow({parent: parent, target: tip[0]});

                if (!isNaN(disappear))
                {
                    setTimeout(function ()
                    { 
                    	that.fadeOut(speed,onclose ,{parent: parent, target: tip[0]});  
                    }, disappear);
                }
                else if (disappear == "self" || disappear == "other")
                {
                    $(document).click(function (e)
                    {
                        if (disappear == "self" && e.target == text[0])
                        {
                        	that.fadeOut(speed,onclose, {parent: parent, target: tip[0]});
                        	$(document).unbind("click");
                        }
                        else if (disappear == "other" && e.target != tip[0])
                        {
                        	that.fadeOut(speed,onclose,{parent: parent, target: tip[0]});
                        	$(document).unbind("click");
                        }
                    });
                }
                else if (disappear == "lost-focus")
                {
                    $(parent).focusout(function ()
                    {
                    	that.fadeOut(speed,onclose,{parent: parent, target: tip[0]});
                    	$(parent).unbind("focusout");
                    });
                }
            });
        },
        fadeOut : function(speed,onclose,param){
        	var tip = $("#" + this.id);
        	 
  	       	if(this.options["borderred"] && !this.multiple){ 
  	       		
  	       	   $(this.parent).removeClass("err_border");
  	       	   
  	    	}else if(this.multiple){
  	    		
  	    		$(this.parent).parent(".controll").removeClass("err_border");
  	    		
  	    	}  
  	       	
        	 tip.fadeOut(speed, function ()
             {
	             if (!!onclose)    onclose(param);
            }); 

        },
        close: function ()
        { 
            var tip = $("#" + this.id);
            var parent = this.parent; 
            var onclose = this.options.onclose; 
            this.fadeOut(this.options.speed,onclose,{parent: parent, target: tip[0]}); 
        }
    };
    
  //---------------------------------------对外开放校验 start-----------------------------------------------------------------------
    $.fn.easytip = function (options,container)
    {
        var tip = new _easytip(this, options,container);

        return tip.init();
    };
  //---------------------------------------对外开放校验  end-----------------------------------------------------------------------
})(jQuery, window, document);